<?php
namespace app\admin\controller;
use think\console\Input;

use think\Request;

use think\Controller;
use think\Db;
class Imgtable extends Controller
{
   public function imgtable()
   {
   	$list=Db::name("jf_class")
   	         ->paginate(2);
            
            $page = $list->render();

            $this->assign('list',$list);
            $this->assign('page', $page);
      return $this->fetch();
   }
   public function class_add()
   {
   	  $request=Request::instance();
   	  if($request->has('sub','post'))
   	  {
   	    
   	     $c_name=$request->post('c_name');
   	     $c_slogan=$request->post('c_slogan');
   	     $c_bteam=$request->post('c_bteam');
   	     $c_steam=$request->post('c_steam');
   	     $data=[
   	           
   	           'c_name'=>$c_name,
   	           'c_slogan'=>$c_slogan,
   	           'c_bteam'=>$c_bteam,
	   	       'c_steam'=>$c_steam,
	   	        	           
   	     ];
   	   $result=Db::table('jf_class')->insert($data);
   	   if($result)
   	   {
   	      $this->success('新增成功','Imgtable/imgtable');
   	   }
   	   else 
   	   {
   	      $this->error('新增失败');
   	   }
   	  }
   	  else 
   	  {
   	     $c_id=input('?param.c_id');
   	     $jf_class=Db::table('jf_class')->where('c_id',$c_id)->find();
   	     return $this->fetch('class_add',[
   	                             'jf_class'=>$jf_class
   	         ]);
   	  }
      //return $this->fetch(); 
   }
   public function class_update()
   {
  	$request=Request::instance();
  	if ($request->has("sub","post"))
  	{
	     $c_id=$request->post("c_id");
	     $c_name=$request->post('c_name');
   	     $c_slogan=$request->post('c_slogan');
   	     $c_bteam=$request->post('c_bteam');
   	     $c_steam=$request->post('c_steam');
   	     $data=[
   	           'c_id'=>$c_id,
   	           'c_name'=>$c_name,
   	           'c_slogan'=>$c_slogan,
   	           'c_bteam'=>$c_bteam,
	   	       'c_steam'=>$c_steam,
	   	        	           
   	     ];    
	     $result=Db::table("jf_class")
		         ->update($data);
	  	if($result)
		  {$this->success("修改成功","Imgtable/imgtable");}
	    else 
		  {$this->error("修改失败");}
	  	}
  	else 
  	{
	  	$c_id=$request->param("c_id");
	  	$data=['c_id'=>$c_id];  
		$list=Db::name("jf_class")
			  ->where('c_id',$c_id)
	          ->find();
	     return $this->fetch('class_update',[
               'list'=>$list,
       ]);        
  	}
   }
   public function class_delete()
   {
      $request=Request::instance();
      $c_id=$request->param('c_id');
      $data=['c_id'=>$c_id];
      $result=Db::table('jf_class')->delete($data);
       if($result)
      {
        $this->success('删除成功','Imgtable/imgtable');  
      }
      else 
      {
        $this->error('删除失败');
      }
      
   }
}